<?php
/**
 * Created by PhpStorm.
 * User: wangwenfan
 * Date: 2018/7/26
 * Time: 15:41.
 */

namespace App\Service;

use App\Models\Base\ServerList;

class ServerService
{
    /**
     * 游戏区服ID集合.
     *
     * @return \Illuminate\Support\Collection
     */
    public static function serverIds()
    {
        return ServerList::all()->pluck('server_id');
    }

    /**
     * 获取区服名.
     *
     * @param $server_id
     *
     * @return mixed
     */
    public static function getServerName($server_id)
    {
        $data = ServerList::where('server_id', $server_id)->pluck('name');
        if ($data->isEmpty()) {
            return '';
        }
        $names = $data->all();

        return $names[0];
    }

    /**
     * 带sid的服务器名.
     *
     * @param $server_id
     *
     * @return string
     */
    public static function getReServerName($server_id)
    {
        return 'S'.$server_id.'_'.self::getServerName($server_id);
    }

    /**
     * select服务器列表.
     *
     * @return array
     */
    public static function getServerList()
    {
        $servers = ServerList::all()->pluck('name', 'server_id')->all();
        $data = ['-1' => '全服'];
        if ($servers) {
            foreach ($servers as $key => $val) {
                $data[$key] = $val;
            }
        }

        return $data;
    }
}
